// pages/参加人员/参加人员.js
Page({

  data: {
    participants: [],
    project_id: ''
  },

  onLoad(options) {
    const app = getApp()
    this.setData({
      project_id: options.project_id
    })
    wx.request({
      url: app.globalData.root_url + 'get_participants_detail/?participants=' + options.participants,
      method: 'GET',
      success: (res) => {
        this.setData({
          participants: res.data
        })
      }
    })
  },

  delete_participant(event) {
    const app = getApp()
    const that = this
    wx.showModal({
      title: '删除报名人员',
      content: '是否删除该报名人员',
      complete: (res) => {
        if (res.confirm) {
          wx.request({
            url: app.globalData.root_url + 'quit_project/?project_id=' + that.data.project_id + '&user_id=' + event.currentTarget.dataset.participant_id,
            method: 'POST',
            success: (res) => {
              if(res.data === 1) {
                wx.showModal({
                  title: '删除报名人员',
                  content: '删除成功',
                  showCancel: false,
                  complete: (res) => {
                    if (res.confirm == 1) {
                      that.data.participants.splice(that.data.participants.findIndex(item => item === event.currentTarget.dataset.participant_id), 1)
                      that.setData({
                        participants: that.data.participants
                      })
                      console.log(that.data.participants)
                    }
                  }
                })
              }
            }
          })
        }
      }
    })
  }
})